Skip to content

MCP profiles: follow-ups for Codex and the T3 tool rule (#812, #814, #918) - #961

Merged
scuttletoby merged 5 commits into
mainfrom
fork/mcp-profile-followups-batch9
Nov 22, 2026
Merged

scuttletoby merged 5 commits into
mainfrom
fork/mcp-profile-followups-batch9

Conversation

@scuttletoby

@scuttletoby scuttletoby commented Nov 22, 2026 •

Copy link
Copy Markdown
Owner

Follow-ups to the fork's MCP profiles (server, Claude and Codex adapters, settings), from the lens reviews of #804 and #827.

Fixes #812
Fixes #918
Part of #814 (umbrella #875). #814 stays open: its item 8 (plugin servers) is declined below and needs an owner decision.

Security

This touches what tools an agent gets. Every change keeps the narrow default or narrows further, with one mild exception that is called out:

  • Mild widening (Claude, MCP profiles PR 4 (T3 tool groups): follow-ups from the #806 lenses #812 item 2): a T3 tool set is now fixed when Claude's new process opens, not when the plan is worked out. If a turn keeps the live process (a continuation, or it is refused while background work still runs), that process keeps the set its own turn fixed until a new process opens. Before, a narrower set could land early, while the old process was still running with its old tools. That early set never matched what the process was actually allowed, so it is dropped. One exception: a turn whose plan has the same key as the plan the thread's live process opened with fixes that set at once (the key carries the T3 groups, so it is exactly the process's set, never wider). That is how a good turn after a refused one gets its set back on the reused process.
  • Narrowing: per-call checks on MCP Apps calls (mcpServer/tool/call, mcpServer/resource/read), elicitations from servers outside the profile are declined, a user's own server named like T3's is switched off, and turns on threads T3 has not seen are adopted or stopped while a narrowed profile is in use. A request that comes in while a Codex-started turn is fixing its set now waits for that set instead of using the set from before. The hold lasts 10 s at most from when the turn started; a hold still there then is dropped and the thread keeps only the ungrouped T3 tools until the late check or its next turn fixes the set (never the set from before).
  • mcpServerStatus/list is not refused: it is read-only.
  • A refused set is never remembered as the thread's set (it is reused for 5 s at most), so a one-off read error no longer lasts the turn. That is fail-closed for those 5 s, never wider.

Every point

#812 (Fixes)

  1. Settings help text: done. Under the T3 tool groups, Settings now says a profile is not a sandbox (MCP_NOT_A_SANDBOX_NOTE).
  2. Claude fixes the set before the turn is known to start: done. The plan's options getter fixes the set (fixedWhenOpened in claudeMcpProfile.ts). ClaudeAdapterV2 reads them only to open a new process.
  3. A t3Tools-only change restarts the Claude process: declined, kept as it is. Pushing notifications/tools/list_changed instead would (a) still cost the prompt cache, because the tool list is part of the cached prefix, (b) change the tools of background work in the middle of its run, which the restart-on-change rule exists to stop, and (c) rely on Claude Code re-reading the list on list_changed mid-session, which is not verified. The restart is the safe and known path.
  4. McpToolExposure.ts import chain: done. mcpT3ToolFilter.ts is now a light module (Effect and McpInvocationContext only). The rule (mcpT3ToolRule.ts) installs its check into it. .github/fork-seams.json is updated to match. A test pins the module's imports.
  5. A Refused set from a one-off read error lasts the turn: done. See Security.
  6. Design doc §6: the design doc is in the owner's private research notes, not in this repo. It has been updated there: sets are kept per thread, in memory, at most 4096, not on the credential.
  7. Cap of 4096 remembered sets: documented in docs/fork/README.md (server.mcpProfiles).

#814 (stays open)

  1. MCP4/MCP5 turn-check split: done in MCP profiles: T3 tool groups on T3's MCP server, for every provider #827.
  2. MCP Apps calls are not checked: done. mcpServer/tool/call and mcpServer/resource/read go through the thread's profile, and a server it leaves out is refused.
  3. A user's own server named t3-code / t3-code-direct: done. Only the T3 servers the load actually carries count as T3's (codexCarriedT3McpServers). A user's server with the same name is switched off like any other.
  4. The store refusal also hits all threads: done, on Codex only: a thread the store does not have yet is read again after 250 ms, 500 ms and 1 s. After the last attempt, the refusal stands (fail closed).
  5. The narrowed latch: done. A thread T3 has not seen (for example a sub-agent from before a restart) is adopted by asking Codex for its parent (thread/read).
  6. Gate MCP tool calls per call: done. An elicitation from a server outside the thread's profile is declined. Codex only sends one when its approval policy asks, so this check covers those turns. The per-thread enabled = false config remains the main guard.
  7. Edges of the turn watch: documented in docs/fork/README.md ("Edges of the Codex turn check"). A stopped turn can run briefly before the interrupt lands, and a turn can end before its check finishes. The comment's follow-up (stop a turn on an unknown thread unless it is adopted within a short wait) is done: the thread is adopted, or after 5 s the turn is stopped.
  8. Plugin servers: declined for now. Turning one off needs plugins."<id>".mcp_servers.<name>.enabled = false in the thread's load config. Codex does not check that key's shape before the load, so a wrong or stale plugin id can make Codex refuse the whole thread load instead of just that server. Today every turn is refused while such a server is on (fail closed), which is safe. This needs an owner decision, so MCP profiles part 5 (Codex): follow-ups from the lens reviews #814 stays open.

#918 (Fixes)

  1. A Codex-started turn fixes its set a few ms late: done. watchTurn's forked check takes a hold on the thread (holdT3ToolSet) as it starts, before the handler returns, and T3's MCP server makes the thread's requests wait for it. The hold is taken and released with acquireUseRelease inside the forked fiber, so a closed scope takes none and every end releases it; it also carries a 10 s bound (see the review round below).
  2. Sub-agent and goal-set turns re-fix the set: done. These turns are checked but do not fix the set.
  3. A turn on an unseen thread keeps its last set: done. While narrowed, it is adopted (5 s wait) or stopped.
  4. Requests that come from no thread see every T3 tool: a known limit, kept and documented in docs/fork/README.md.
  5. Do not remember a failed read: done (the same change as MCP profiles PR 4 (T3 tool groups): follow-ups from the #806 lenses #812 item 5).
  6. Profile worked out three times per turn: done. The turn check provides its result as CurrentTurnMcpProfile. The Codex wrapper reads that result and no longer works the profile out again: no thread/read, and no second status list.

Each fix fails without it

Each fix was undone on its own and its test file run:

Fix undone Test that fails
#918.1: no hold in watchTurn codexMcpProfile.test.ts › a turn Codex starts holds T3's requests until its set is fixed
#918.2: sub-agent turns fix the set codexMcpProfile.test.ts › a sub-agent's turn, or a goal set active, checks but leaves the parent's set
#918.2: goal-set turns fix the set the same test
#918.3 / #814.5: no adopt-or-stop for an unseen thread codexMcpProfile.test.ts › a turn on a Codex thread T3 has not seen: adopted when Codex names its parent, else stopped (it hangs to the timeout)
#918.6: Codex works the profile out again codexMcpProfile.test.ts › T3's own turn reads the profile the turn check worked out, once per turn
#918.6: the turn check does not pass its profile on mcpProfileTurnCheck.test.ts › Codex (in MCP_PROFILE_DRIVERS): a narrowed t3Tools gets exactly that set…
#814.2: MCP Apps calls not checked codexMcpProfile.test.ts › MCP Apps calls and elicitations to a server outside the profile are refused
#814.6: elicitations not declined the same test
#814.3: every T3 name counts as T3's codexMcpProfile.test.ts › a server of the user's named like T3's is switched off unless T3 carries it
#814.4: no store-lag retry codexMcpProfile.test.ts › a thread the store does not have yet is read again before it is refused
#812.5 / #918.5: a refused set is remembered mcpT3ToolFilter.test.ts › a refused set is not remembered: it is reused briefly, then worked out again
#918.1: the rule ignores the hold mcpT3ToolFilter.test.ts › a hold never released: the request is refused, not given the set before
#812.2: Claude fixes the set at once claudeMcpProfile.test.ts › the set is fixed only once the plan opens a process: a turn that keeps the old one keeps its set
#812.4: the filter imports a toolkit mcpT3ToolFilter.test.ts › imports no toolkit, profile resolver or store
#812.1: the Settings note removed McpProfileSettings.browser.test.tsx › says under the T3 tool groups that a profile is not a sandbox
R1.1: no re-fix on the same plan key claudeMcpProfile.adapter.test.ts › runs again after a refused turn: the next good turn on the same process gets its set back (sets were Groups, Refused, Refused)
R1.2: hold taken before forkIn codexMcpProfile.test.ts › stopped half-way: a turn Codex starts as the client closes leaves no hold
R1.2/R1.3: per-request 10 s wait, holds never dropped mcpT3ToolFilter.test.ts › tools/list waits once for the hold, not once per tool; and › a hold past its bound is dropped: later requests do not wait, later turns start fresh (both fail on the old rule and sets, both need no socket)

Each run had exactly that one test failing in its file; all others passed. The R1 rows were written first and seen failing on the round-0 head before the fix. codexMcpProfile.test.ts › stopped half-way: a turn's check interrupted mid-way releases its hold is a guard that already passed (the ensuring covered that path).

Review round 1

Finding Done
MAJOR (both lenses): a refused Claude turn's set sticks while the process is reused Fixed. claudeMcpProfile.ts remembers the plan key each thread's process opened with (set by the options getter, bounded at 4096 threads). A later plan with the same key fixes its set at once, since the adapter keeps that process without reading options. Chosen over closing the process on a refusal, which would kill the background work the refusal exists to protect. Test over three turns: Groups, Refused (settings read fails once), Groups on the same process.
MAJOR (state): hold taken before forkIn, leaked on a closed scope; tools/list waits once per tool Fixed. The hold is taken inside the forked check with acquireUseRelease (the fiber starts at once, so it is still taken before the handler returns). Each hold records its bound (until); a request waits at most until then, so a list request waits once in all, not once per tool.
minor: a hold never released stays in the map Fixed. A hold past its bound is dropped by the first request that finds it so (dropT3ToolSetHold), which fixes a refused set with the "try again" reason, and a later holdT3ToolSet starts a fresh hold rather than joining a stale one.
minor: CurrentTurnMcpProfile keyed by thread Comment on mcpTurnProfile.ts and where it is provided (mcpProfileTurnCheck.ts): nothing forked inside a turn start may outlive it; fork long-lived work from the session.
minor: README; McpHttpServer.ts names the rule McpT3ToolFilter README says the hold covers only the profile step (T3's tools carry the new set while the server step runs) and describes the bound. The import is now McpT3ToolRule.

State question

  • Old settings without the new keys: no settings keys were added. The only new user-facing text is the Settings note.
  • A profile removed while a thread uses it: the thread's next turn (or the next request worked out from the settings) gets a refusal, so it keeps only the ungrouped T3 tools (fail closed). A running Claude process keeps the set its own turn fixed until it closes. That is the mild widening above.
  • Restart: fixed sets, holds, the refused-set cache, and Codex's known/children maps are all in memory, so they start empty. After a restart, a request from a thread with no set works the set out from the settings, and a Codex turn on a thread not seen since the restart is adopted through thread/read or stopped. Codex reloads each thread with its per-thread config, as before.
  • Stopped half-way: a hold is taken only by a check that runs (a closed scope starts none) and released by acquireUseRelease however the check ends, so an interrupted or failed check never leaves requests waiting (tested: scope closed before turn/started, and closed mid-check). A hold that is still not released 10 s after it was taken (a check stuck that long) is dropped: requests waited on it once, are refused, and the thread keeps only the ungrouped T3 tools until the late check or the next turn fixes its set; it never falls back to the set from before. A request whose set read fails is refused, and nothing is remembered.
  • Runs again: fixing the same set twice is a no-op. Each turn fixes its own set; on Claude, a good turn after a refused one on the same process fixes the process's set again (tested over three turns).
  • Old state (process reused): a Claude process kept across turns keeps the set of the plan it opened with; a turn with that plan re-fixes exactly that set.

Checks

Run locally:

  • server vitest, 176 tests in 6 files: mcpT3ToolFilter, claudeMcpProfile, claudeMcpProfile.adapter, personOnlySettings, codexMcpProfile, mcpProfileTurnCheck
  • review round 1: 161 tests in claudeMcpProfile, claudeMcpProfile.adapter, codexMcpProfile, mcpProfileTurnCheck, personOnlySettings, and the 8 mcpT3ToolFilter tests that need no socket, all pass. Not run locally in round 1 (loopback blocked on that machine): the withServer tests in mcpT3ToolFilter.test.ts and holdWork.boot.test.ts; CI runs them.
  • workAdmission.startPaths.test.ts and holdWork.boot.test.ts, which the first CI run caught. The Codex turn wrap is now named turnStart, so the start-paths guard (every file naming startTurn) is unchanged. The boot test now expects the rule's span McpT3ToolRule.make.
  • the web browser test for McpProfileSettings (10 tests)
  • server typecheck
  • vp lint, vp fmt --check, knip
  • the fork seam check

General vs project

All general: this is the fork's MCP profile feature, for every user of the fork. There are no project facts and no new config. Upstream files: only the fork's own lines in McpHttpServer.ts change (the import now names the rule's module fork/mcpT3ToolRule.ts as McpT3ToolRule, and the fork's layer line uses that name), and the seam text in .github/fork-seams.json changes to match. McpToolExposure.ts is not touched.

🤖 Generated with Claude Code

scuttletoby and others added 2 commits November 22, 2026 14:08
…918)

- Codex: a turn Codex starts holds the thread's T3 requests until its set
  is fixed; sub-agent turns and goal sets are checked but never fix the
  parent's set; a turn on an unseen thread is adopted by thread/read or
  stopped after a short wait; T3's own turn is not checked twice and reads
  the profile the turn check worked out (once per turn).
- Codex: MCP Apps calls (tool/call, resource/read) to a server outside the
  profile are refused, and its elicitations declined.
- Codex: only the T3 servers a load carries are exempt, so a user's server
  named t3-code is switched off like any other.
- Codex: a thread not yet in the store is read again (250 ms, 500 ms, 1 s)
  before the refusal stands.
- T3 tool rule: a refused set worked out by a request is reused 5 s and never
  remembered; tool_search imports only a light filter module.
- Claude: the T3 tool set is fixed as the query opens.
- Settings help text and docs (4096 cap, Codex edges, not a sandbox).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…he rule's span

The start-paths guard lists every file that names startTurn, and the boot test
lists the fork layers' spans; both now match the rule module.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: state · reviewer: lens agent · read at: 54afc81
covered: the whole diff (codexMcpProfile.ts, mcpT3ToolRule.ts, mcpT3ToolFilter.ts, mcpT3ToolSets.ts, mcpTurnProfile.ts, mcpProfileTurnCheck.ts, claudeMcpProfile.ts, the settings note, docs/fork/README.md, fork-seams.json), the call sites in CodexAdapterV2.ts (openSession, startTurn, callTool/readResource, the elicitation handler) and ClaudeAdapterV2.ts (the plan, the keep-process exits, the process open), effect's forkIn and the MCP list filter; issues #812, #918, #814 with their comments, and the PR body.
checks: ran the changed test files that need no socket: claudeMcpProfile (55), claudeMcpProfile.adapter (10), codexMcpProfile (47), mcpProfileTurnCheck (28), personOnlySettings (18) all pass; in mcpT3ToolFilter, the 6 tests that need no socket pass. Not run here (loopback blocked): the mcpT3ToolFilter tests that use withServer (/mcp over HTTP, 12 tests, among them the hold, hold-timeout and refused-reuse tests), holdWork.boot.test.ts, and the web browser test. Undid fixes one at a time; each turned its named test red with 1 failure in its file: #918.1 hold in watchTurn, #918.2 sub-agent and goal fix, #918.2 goal alone, #814.3 carried servers, #814.4 store-lag retry, #812.2 Claude fixing at once. Two throwaway probes (not pushed, files restored) back the majors below.
state: runs again: fixing the same set twice does nothing, and each turn fixes its own. Empty or old state: no new settings keys; holds, fixed sets, the refused-set cache and Codex's known/children/carried maps live only in memory, so a server restart starts them empty. A thread the store has not seen yet is read 3 more times (about 1.75 s), then refused. Sub-agent and goal-set turns are checked but leave the parent's set. A settings read that fails mid-turn refuses, on Codex and in the rule. Stopped half-way is where it breaks: a hold can be taken and never released (major 1), and on Claude a one-off refused set stays while the process is kept (major 2). Both fail closed. I found no way for an agent to get a T3 tool or an outside server its profile leaves out.
blocker: none
major: a hold that is never released lasts until the server restarts, not 10 s. watchTurn takes the hold in Effect.suspend, then forks the check with Effect.forkIn(scope) (apps/server/src/fork/codexMcpProfile.ts:568-573). The release is inside the forked effect, in its ensuring. When the client's scope is already closed (a turn/started dispatched while the session shuts down), forkIn returns a fiber that never started (effect internal/effect.ts forkIn: "A closed scope gets an unstarted fiber"), so the ensuring never runs. The same happens if the handler is interrupted between the hold and the fork. Nothing else deletes a hold (mcpT3ToolSets.ts:89-104), and later holds only raise its count. From then on, every T3 request of that T3 thread waits 10 s and is refused (mcpT3ToolRule.ts:193-197), whatever later turns fix, also after a new app-server opens or the thread moves to another provider, until T3 restarts. A tools/list waits once per tool, because the list filter runs the rule one tool after another (effect ai/internal/mcpCore.ts filterList, Effect.filter with no concurrency), so with dozens of T3 tools the list hangs for many minutes. Probe: closing the client's scope, then emitting turn/started for a loaded thread, leaves t3ToolSetHold("t") defined. The PR body says "a hold is released in ensuring, so an interrupted or failed check never leaves requests waiting", which does not hold for this path. Fix: give each hold a deadline (holdT3ToolSet records when it was taken, and t3ToolSetHold drops holds older than T3_TOOL_SET_HOLD_WAIT_MS), or take the hold inside the forked fiber. Also wait for a hold once per request, not once per tool. Add a test that closes the scope before turn/started and checks that no hold is left.
major: on Claude, a one-off refused set stays for the life of the live process, not one turn. planFor fixes a Refused set at once when the profile cannot be worked out (apps/server/src/fork/claudeMcpProfile.ts:734). A good set is fixed only when a new process opens (:743, fixedWhenOpened). The next turn with the same plan key keeps the live process (apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts:13144 and :13204) and never reads options, so the Refused set stands. That process keeps only the ungrouped T3 tools across its turns until something else replaces it. Before this PR, the next good turn fixed the real set at once. Trigger: any one-off settings read failure, or a parent the store does not give yet, at one Claude turn start. Probe: plan with options read (Groups), then a refused plan (Refused), then the same good plan with options not read: still Refused. This undoes the aim of #812 item 5 ("a one-off read error no longer lasts the turn") for Claude. Fix: remember the set each process opened with, under its plan key, and when a later plan has the same key as the live process, fix that set again (no wider than what the process already had). Add a test for refused, then good, with the process kept.
minor: the hold covers only profileStep. serverStep (Codex's mcpServerStatus/list) runs after the release, so the turn's T3 requests go ahead before the outside-server check finishes. The README's "edges" paragraph covers outside servers, but could say that T3's own tools already carry the new set while the server check runs.
minor: CurrentTurnMcpProfile is a Context.Reference set around the whole run(input), so any fiber forked inside a turn start inherits it. Today nothing in CodexAdapterV2's startTurn path forks a long-lived fiber that later calls the wrapped client, so it is never read stale. A comment at mcpProfileTurnCheck.ts where it is provided, saying not to fork long-lived work inside, would keep it that way.
minor: socket-bound tests not run here: the mcpT3ToolFilter withServer tests (including "a hold never released" and "a refused set is not remembered") and holdWork.boot.test.ts. Their CI run is the evidence for them.

🤖 Generated with Claude Code

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: lens agent (Claude) · read at: 54afc81
covered: the whole diff (20 files), issues #812, #918 and #814 with comments, the PR body (per-item table, declined 812/3 and 814/8, the security note). Paths a call can take: T3 tools/list and tools/call through mcpT3ToolRule.ts (hold, refused-set reuse, worked-out set); tool_search through the light filter; Codex turn/start, Codex-started turns (own, sub-agent, unseen thread), thread/goal/set, thread/resume of an unseen sub-agent, MCP Apps mcpServer/tool/call / mcpServer/resource/read (the adapter's callTool, readResource and app capture all pass threadId and server, the names the wrapper reads), elicitations (the adapter registers its handler on the wrapped client), requests with no thread, a user server named t3-code; Claude's plan options getter against ClaudeAdapterV2's reuse and replace paths; the seam entry for McpToolExposure.ts and the import line in McpHttpServer.ts (a pending file).
checks: ran codexMcpProfile, claudeMcpProfile, claudeMcpProfile.adapter, personOnlySettings and mcpProfileTurnCheck tests (158 passed), and the 7 non-socket tests of mcpT3ToolFilter.test.ts (passed). Not run here, because loopback is blocked: the 11 withServer tests in mcpT3ToolFilter.test.ts (among them the refused-set and both hold tests) and holdWork.boot.test.ts. CI ran them: Test 1/2 green. Undid 6 fixes one at a time and ran the file: #918.1 no hold, #918.2 sub-agent turns fix the set, #814.2 MCP Apps calls not checked, #814.3 every T3 name counts as T3's, #814.6 elicitations not declined, #812.2 Claude fixes the set at once. Each made exactly the named test red, and every other test in the file stayed green. Repro for the major: a scratch adapter test (not pushed) that runs 3 Claude turns on a narrowed profile, with the settings read failing once on turn 2. Run on this head and on main's claudeMcpProfile.ts.
state: runs again: fixing the same set twice is a no-op; a second release of a hold does nothing. Stopped half-way: a hold is released in ensuring; an interrupted Claude plan now leaves the last set (tested). Old or empty state: after a restart the sets, holds, refused cache and Codex maps start empty, and the set is worked out from the settings (never wider). One state edge is wrong, the major below: on Claude, a refused turn's set stays while the live process is reused.
blocker: none
major: Claude: one refused turn leaves the thread stuck on the Refused set (only the ungrouped T3 tools) for as long as its live process is reused, not just for the refused turn (apps/server/src/fork/claudeMcpProfile.ts:740 and :743, with apps/server/src/orchestration-v2/Adapters/ClaudeAdapterV2.ts:13204). A refusal fixes Refused at once and leaves the old process running. The next turn resolves fine with the same plan key, so ClaudeAdapterV2 returns existing without reading plan.options, and the getter that would fix the Groups set never runs. Repro: turn 1 opens on profile lean; turn 2 meets a one-off settings read error and is refused; turn 3 (settings readable, same profile) reuses the process. Set after each turn on this head: Groups, Refused, Refused, and it stays Refused until the process closes. On main's claudeMcpProfile.ts: Groups, Refused, Groups. The same happens after a profile edit that refuses one turn and is then set back. This fails closed, so it is not a widening. But it is new in this PR, and it goes against the PR's own point that a one-off read error must not last (#812.5 / #918.5). A fix: when a turn reuses the live process with the same plan key, fix the plan's set again. The key carries the T3 groups, so that set is the one the process opened with. Add a test of that order of turns.
minor: a hold that is never released is never removed (apps/server/src/fork/mcpT3ToolSets.ts:96-102). Later holdT3ToolSet calls on that thread join it (count never reaches 0), so every request of the thread waits 10 s and is refused until a restart, not just the requests of one turn. The PR's state note says it waits 10 s and then refuses. It fails closed, but one leaked hold (for example, the check's fiber interrupted before its ensuring is in place, codexMcpProfile.ts:568-573) disables the thread's grouped T3 tools for good. A fix: drop a timed-out hold from the map in the rule, or give each hold a deadline.
minor: CurrentTurnMcpProfile (mcpProfileTurnCheck.ts:132) is keyed by thread, not turn. Any fiber forked inside startTurn that outlives the turn would keep this turn's profile for later Codex-started turns of the same thread, which would widen them after a narrowing. I found no such fork today: the client opens in openSession and the notification handlers fork from there. A short comment on mcpTurnProfile.ts saying it must stay that way would keep this from coming back.
minor: McpHttpServer.ts:99 still names the rule's module McpT3ToolFilter (import * as McpT3ToolFilter from "../fork/mcpT3ToolRule.ts"). It is harmless, but a reader looks for the rule in the filter file.
Security, item by item: I found no way for an agent to get a T3 tool or an outside server its profile leaves out. The MCP Apps calls and elicitations are gated, and a thread T3 cannot match is refused while narrowed. A tool tool_search returns still has to pass the rule on tools/call, which waits for a hold. A Codex-started own turn holds the thread's requests until its set is fixed; a sub-agent's turn uses its parent's set. A user server named t3-code is switched off unless the load carries T3's (the adapter sends the dotted mcp_servers.t3-code key the wrapper reads). Requests with no thread are the documented limit (#918.4). The Claude widening the PR calls out is the design #812.2 asked for: only a continuation, or a turn refused for background work, keeps the old process's set, and any change of T3 groups changes the plan key, so a new process opens. Declined items: 812/3 (restart on a T3-groups change) is the conservative path. 814/8 (plugin servers) is safe as is: an enabled plugin server appears in mcpServerStatus/list, so every turn is refused, MCP Apps calls to it are refused and its elicitations are declined. The edge is the documented brief run of a Codex-started turn before its stop.
fork-ci at read time: every check on this head completed, all green or skipped (Lint, Build and Typecheck, Test 1/2, Test Web 1/2, Fork kit tests, Workflow lint and upstream drift).

🤖 Generated with Claude Code

scuttletoby and others added 2 commits November 22, 2026 16:31
… bounded and never leak

- Claude: a turn whose plan matches the one the thread's live process opened
  with fixes that set again, so a good turn after a refused one gets its set
  back on the reused process (was: Refused until the process closed).
- Codex: the turn/started hold is taken inside the forked check with
  acquireUseRelease, so a closed scope takes none and every end releases it.
- Holds carry a bound: a request waits at most until it, so tools/list waits
  once, not once per tool; a hold past it is dropped and the thread keeps
  only the ungrouped T3 tools until a turn fixes its set.
- Comments on CurrentTurnMcpProfile's per-turn assumption; README says the
  hold covers only the profile step; McpHttpServer imports the rule as
  McpT3ToolRule.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: state r2 · reviewer: lens agent · read at: 005eb32
verdict: safe to merge
covered: the fix diff since round 1 (005eb32 on top of the main merge 83ff22d: claudeMcpProfile.ts, codexMcpProfile.ts, mcpT3ToolRule.ts, mcpT3ToolSets.ts, mcpTurnProfile.ts, mcpProfileTurnCheck.ts, McpHttpServer.ts, the README and the test files), both round 1 reports, the PR body ("Review round 1" table and the state section), and ClaudeAdapterV2's reuse paths (continuation, same queryPolicyKey, refusal while background work runs) against the new opened-plan-key check.
checks: loopback works on this machine, so this round ran the socket tests round 1 could not: mcpT3ToolFilter.test.ts 20/20 (all 13 withServer tests among them, including the hold, hold-bound, refused-reuse and list-waits-once tests) and holdWork.boot.test.ts 2/2. The other changed files, one at a time: claudeMcpProfile.adapter 11/11, codexMcpProfile 49/49, claudeMcpProfile 55/55, mcpProfileTurnCheck 28/28. Two "fails without" claims checked by undoing the fix, each with exactly 1 failure in its file: R1.1, the same-plan-key re-fix removed from planFor, fails "runs again after a refused turn: the next good turn on the same process gets its set back"; R1.2, the hold taken before forkIn again (holdT3ToolSet in the handler, released in ensuring), fails "stopped half-way: a turn Codex starts as the client closes leaves no hold". Files restored. A throwaway probe on mcpT3ToolSets (not pushed) backs the first minor.
state: runs again: Claude Groups, Refused, Groups on a reused process now holds (tested), because a plan with the key the thread's process opened with fixes that set at once; the key carries the T3 groups and the set is worked out from the settings of this turn, so it is never wider than the current profile or the live process. A continuation or a turn refused for background work, with a different key, fixes nothing, so the live process keeps its own set. Codex: a second hold within the bound joins the first; one after the bound starts a fresh hold, and an old release never removes the newer hold (checked: release compares the map entry). Stopped half-way: the hold is now taken inside the forked fiber with acquireUseRelease, so a closed scope takes none and an interrupted check releases it. A hold never released costs one wait of at most 10 s from when it was taken (also for tools/list: one wait, not one per tool), is then dropped and the thread keeps Refused (only the ungrouped T3 tools) until the late check or its next turn fixes a set. A late check after the drop fixes its own set and its release is a no-op. Old state: the opened-plan-key map is memory only and bounded at 4096; a thread evicted from it after a refused turn stays Refused on its reused process until a new process opens (fail closed, never wider). After a restart every map starts empty and Claude and Codex processes go with the server. Wider than its own: I found no path in this diff. Stuck refused until restart: no; the worst is Refused until the thread's next turn (see the minors).
round 1, fixed: a hold never released lasted until restart and made tools/list wait once per tool (now bounded at 10 s, taken inside the fork, dropped after its bound, one wait per request)
round 1, fixed: a refused Claude turn's set stuck while the process was reused (now re-fixed on the same plan key)
round 1, fixed: the CurrentTurnMcpProfile comment and the McpHttpServer import name
blocker: none
major: none
minor: a drop can overwrite a set a newer turn already fixed (apps/server/src/fork/mcpT3ToolSets.ts:99 and :145-147). A hold joined within its bound keeps the first turn's until, and a T3-started turn fixes its set without touching a hold. So if turn 1's check is stuck, turn 2 (joined, or started by T3) fixes its set, and a request after that still waits for turn 1's hold until its bound, then dropT3ToolSetHold keeps Refused over turn 2's set. Probe: hold at 0, join at 5 s, fix Groups, release the join, a request at 7 s waits 3 s and the drop leaves Refused. It fails closed and lasts until the next turn or the late check, and it needs a profile check stuck for seconds (a store or settings stall), so it is not a blocker. A fix: have the drop keep Refused only when no set was fixed after the hold was taken (a per-thread generation or time stamp), or end the hold when a turn of the thread fixes its set.
minor: the late check's fix is last-writer-wins (apps/server/src/fork/codexMcpProfile.ts:370). The docs now say a dropped hold's thread waits for "the late check or its next turn", but a late check that finishes after a newer turn fixed its set overwrites that set with its own, which can be wider if the profile was narrowed between the late check's settings read and the newer turn. This is older than this PR (the watch's fix was never ordered), and it needs a check slower than a whole turn, so it is noted, not held: the same generation stamp would cover it (a check fixes only if no newer turn has).
minor: the narrow window between profileStep's fix and the release in acquireUseRelease: a request whose wait ends in it drops the hold and keeps Refused over the set just fixed (dropT3ToolSetHold's "released meanwhile" check looks at the hold, not at the set). Fail closed, at the 10 s bound only; the generation stamp above would cover it too.
fork-ci at read time: head 005eb32 still running (Build and Typecheck, Lint, Test 1/2, Test Server 1-8, Test Web 1/3, Fork kit tests 1, Release Smoke, Rust pending); passed so far: Test Web 2, Fork kit tests 2, 3 and as root, Fork action and fleet walls tests, Workflow lint and upstream drift, secret scans, Changes, Fork checks ran, No database schema changes. No failures.

🤖 Generated with Claude Code

@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code r2 · reviewer: lens agent (Claude) · read at: 005eb32
verdict: safe to merge
covered: the fix commit since round 1 (005eb32: claudeMcpProfile.ts, codexMcpProfile.ts, mcpT3ToolSets.ts, mcpT3ToolRule.ts, mcpTurnProfile.ts, mcpProfileTurnCheck.ts, McpHttpServer.ts, docs/fork/README.md, and the three test files); the merge of main in 83ff22d touches none of the PR's MCP files. Both round-1 reports and the PR body's "Review round 1" table. Against ClaudeAdapterV2's start path (ClaudeAdapterV2.ts:13128-13294): where the plan is made, the continuation and same-key reuse exits, the background-work refusal, and the one place mcpProfile.options is read (after the old process closed). planKey (claudeMcpProfile.ts:412) against t3ToolSetOf: both come from the same profile.t3Tools, so the same key always means the same groups.
checks: ran claudeMcpProfile, claudeMcpProfile.adapter, codexMcpProfile and mcpProfileTurnCheck (143 passed), personOnlySettings (18 passed), and the 9 tests in mcpT3ToolFilter.test.ts that need no socket, among them the 2 new ones under "the hold bound, without a socket" (passed). Skipped, because loopback is blocked here: the 11 withServer tests in mcpT3ToolFilter.test.ts (they fail here with a connect timeout) and holdWork.boot.test.ts. A second lens on another machine runs them. Undid fixes one at a time and ran the file. (1) Took out the same-key re-fix in planFor: only "runs again after a refused turn…" fails, with sets ['waits'], 'Refused', 'Refused'. (2) Took the hold before forkIn again, with ensuring: only "stopped half-way: a turn Codex starts as the client closes leaves no hold" fails. (3) Put back the round-0 rule (a 10 s wait per request, the hold never dropped): both new hold-bound tests fail. Mutation probe: changed the match to openedPlanKeys.has(thread.id) (no key check, which would allow a widening). The file run fails, but "the set is fixed only once the plan opens a process…" passes when run alone (see minor 1). The worktree was restored after each run.
state: Runs again: fixing the same set twice does nothing, and a second release does nothing. A hold taken after the last one's bound starts fresh, and the old hold's late release does not delete it (mcpT3ToolSets.ts:116). A second drop of the same hold returns false. Stops half-way: on a closed scope, forkIn never starts the fiber, so acquireUseRelease takes no hold. A check interrupted mid-read releases its hold. Both are tested, and the first fails without the fix. A hold still held past 10 s is dropped by the first request that finds it: that request waits once and gets the Refused "try again" set, and later requests do not wait. The thread keeps only the ungrouped tools until the late check or the next turn fixes its set, never the set from before. Old or empty state: openedPlanKeys, holds and sets live only in memory. After a restart, no process lives, so the first good turn opens one and reads options, and no stale key can match a process that does not exist. A key left over from a closed process can only match a plan with the same groups, so it fixes the current set, which the new process then fixes again.
blocker: none
major: none
round 1, fixed (Claude, refused set sticks on a reused process): planFor (claudeMcpProfile.ts:770) re-fixes the set when the plan key equals the key the thread's process opened with. The adapter reads options only after the old process closed, so the recorded key is the live process's key. The key carries the T3 groups, so the set fixed is exactly that process's set, never wider. Continuations and background-work refusals with a different key fix nothing. The fix is at the root and the test fails without it.
round 1, fixed (Codex, hold taken before forkIn): the hold is taken in the acquire of acquireUseRelease inside the forked fiber (codexMcpProfile.ts:571-580). startImmediately still takes it before the handler returns: the old test now asserts asked("t") right after the emit. Release runs however the check ends, and it covers only profileStep.
round 1, fixed (tools/list waits once per tool; a stale hold lasts until restart): a hold records until, and a request waits at most until - now (mcpT3ToolRule.ts:185-204). The first timeout drops the hold and keeps the Refused "try again" set (mcpT3ToolSets.ts:140-149), so later tools in the same list, and later requests, do not wait. If the drop loses the race to a release or to a newer hold, setFor looks again. That can wait once more, on the newer hold, and is still bounded.
round 1, fixed: the comment on CurrentTurnMcpProfile (mcpTurnProfile.ts, mcpProfileTurnCheck.ts:130), the README paragraph (hold covers only the profile step, the bound, the dropped hold), and the import renamed to McpT3ToolRule (McpHttpServer.ts:99, :1481). No other name McpT3ToolFilter points at the rule.
Cap answer (4096, claudeMcpProfile.ts:713-722): evicting a live thread's key only removes the re-fix. That thread is back to the round-1 behaviour, Refused after a one-off refusal until its process closes. It fails closed, never wider. The order is by process open, not by use, so a long-lived process is the first one dropped (minor 2).
minor: the "never wider" guard (the key comparison at claudeMcpProfile.ts:770) is pinned only by state left behind by earlier tests. openedPlanKeys is module-global, and no test hook clears it (T3ToolSets.__testing.clear() does not). With the comparison taken out, "the set is fixed only once the plan opens a process: a turn that keeps the old one keeps its set" (claudeMcpProfile.test.ts:276) fails in a full file run, only because an earlier test recorded a key for thread t. Run alone, it passes. Add a __testing reset for openedPlanKeys. Then add a test where the process opened with one key and a later plan with a different, wider key is kept by a continuation or a background-work refusal: the set must stay the process's set.
minor: keepOpenedPlanKey refreshes a thread's entry only when a process opens (claudeMcpProfile.ts:715), not when a plan matches. After 4096 other process opens, a long-lived process loses its entry first. Refreshing the entry on a match in planFor would order the cache by use, like sets. Fail closed either way.
minor: a narrow race in dropT3ToolSetHold (mcpT3ToolSets.ts:145-147). If a request's 10 s timeout fires after the check's fixT3ToolSet but before its release, the drop still finds the hold and overwrites the fixed set with Refused. No late check is left to fix it again, so the thread keeps only the ungrouped tools until its next turn. It fails closed and needs a check that ends at the 10 s mark. If it matters, skip the drop when the hold's done is already completed, or have the release-side fix win.
fork-ci at read time (head 005eb32): the run is still going: 23 checks green, 9 skipped, 7 pending (Test Server 1, 2, 3, 5 and 6, and Test Web 1 and 3). Green so far: Lint, Build and Typecheck, Test 1/2, Test Server 4, 7 and 8, Test Web 2, Fork kit tests 1-3 and as root, Release Smoke, Workflow lint and upstream drift, and the secret scans. Nothing is red.

🤖 Generated with Claude Code

@scuttletoby
scuttletoby merged commit 1fea24d into main Nov 22, 2026
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#827 follow-ups: Codex tool-set timing and failed-read caching MCP profiles PR 4 (T3 tool groups): follow-ups from the #806 lenses

1 participant